const express = require('express');
const router = express.Router();
const auth = require('../middleware/auth');
const User = require('../models/User');

// 修改用户主题色接口
router.put('/users/theme', auth, async (req, res) => {
  // 修改数据库用户的主题字段
  try {
    const user = await User.findByIdAndUpdate(
      {_id:req.user.userId}, { theme: req.body.theme }, { new: true });
    if (!user) {
      return res.status(404).json({
        code: 500,
        msg: '用户不存在',
        data: null,
      });
    }
    return res.status(200).json({
      code: 200,
      msg: '修改成功',
      data: null
    });
  } catch (err) {
    return res.status(404).json({
      code: 500,
      msg: '用户不存在',
      data: null
    });
  }
}
)
module.exports = router;
